package com.sky.service.impl;

import com.sky.constant.StatusConstant;
import com.sky.entity.Orders;
import com.sky.mapper.DishMapper;
import com.sky.mapper.OrderMapper;
import com.sky.mapper.SetmealMapper;
import com.sky.service.WorkSpaceService;
import com.sky.vo.DishOverViewVO;
import com.sky.vo.OrderOverViewVO;
import com.sky.vo.SetmealOverViewVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.HashMap;
import java.util.Map;

@Service
public class WorkSpaceServiceController implements WorkSpaceService {
    @Autowired
    private OrderMapper orderMapper;
    @Autowired
    private DishMapper dishMapper;
    @Autowired
    private SetmealMapper setmealMapper;

    // 获取订单统计数据
    @Override
    public OrderOverViewVO getOverViewOrders() {
        LocalDate now = LocalDate.now();
        LocalDateTime begin = LocalDateTime.of(now, LocalTime.MIN);
        LocalDateTime end = LocalDateTime.of(now, LocalTime.MAX);

        //已取消订单数量
        Integer cancelledOrders = orderMapper.getOrderCountByStatus(begin, end, Orders.CANCELLED);
        //全部订单数量
        Integer allOrderCount = orderMapper.getOrderCountByStatus(begin, end, null);
        //已完成数量
        Integer completedOrderCount = orderMapper.getOrderCountByStatus(begin, end, Orders.COMPLETED);
        //待派送数量
        Integer deliveringOrderCount = orderMapper.getOrderCountByStatus(begin, end, Orders.DELIVERY_IN_PROGRESS);
        //待接单数量
        Integer waitingOrders = orderMapper.getOrderCountByStatus(begin, end, Orders.PENDING_PAYMENT);

        //封装vo对象并返回
        return OrderOverViewVO.builder()
                .cancelledOrders(cancelledOrders)
                .allOrders(allOrderCount)
                .completedOrders(completedOrderCount)
                .deliveredOrders(deliveringOrderCount)
                .waitingOrders(waitingOrders)
                .build();


    }

    /**
     * 查询菜品总览
     *
     * @return
     */

    @Override
    public DishOverViewVO getOverViewDishes() {
        //已售菜品数量
        Integer sold = dishMapper.getDishCOuntByStatus(StatusConstant.ENABLE);
        //已停售菜品
        Integer discontinued = dishMapper.getDishCOuntByStatus(StatusConstant.DISABLE);


        //封装vo对象并返回封装vo对象并返回
        return DishOverViewVO.builder()
                .sold(sold)
                .discontinued(discontinued)
                .build();
    }

    /**
     * 查询套餐总览
     *
     * @return
     */
    @Override
    public SetmealOverViewVO getOverViewSetmeals() {
        //已售套餐数量
        Integer sold = setmealMapper.getSetmealCountByStatus(StatusConstant.ENABLE);
        //已停售套餐数量
        Integer discontinued = setmealMapper.getSetmealCountByStatus(StatusConstant.DISABLE);


        //封装vo对象并返回
        return SetmealOverViewVO.builder()
                .sold(sold)
                .discontinued(discontinued)
                .build();

    }
}
